﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Locator.Silverlight.Client.Models.ViewModels.Screens;
using Locator.Silverlight.Client.Models.ViewModels.Elements;
using Locator.Silverlight.Client.Models;
using Locator.Silverlight.Client.Models.PersonalLocationsServiceReference;

namespace Locator.Silverlight.Client.Test
{
    [TestClass]
    public class ManagePersonalLocationsViewModelTests
    {
        private static MockPersonalLocationService InitializeMockPersonalLocationService()
        {
            MockPersonalLocationService result = new MockPersonalLocationService();
            result.GetPersonalLocationsResult.Add(new PersonalLocation() { Description = "Home", Id = 0, Latitude = 43.0M, Longitude = -79.0M });
            result.GetPersonalLocationsResult.Add(new PersonalLocation() { Description = "Work", Id = 1, Latitude = 41.0M, Longitude = -78.0M });
            result.GetPersonalLocationResult = new Models.ViewModels.Elements.PersonalLocationViewModel() { Description = "Work", Id = 1, Latitude = 41.0M, Longitude = -78.0M };
            return result;
        }

        [TestMethod]
        public void ManagePersonalLocationsViewModelInit()
        {
            MockPersonalLocationService service = InitializeMockPersonalLocationService();
            using (ManagePersonalLocationsViewModel viewModel = new ManagePersonalLocationsViewModel(new PersonalLocationModel(service)))
            {
                Assert.AreEqual(2, viewModel.UserLocations.Count);
                Assert.AreEqual(0, viewModel.UserLocations[0].Id);
                Assert.AreEqual(1, viewModel.UserLocations[1].Id);
                Assert.AreEqual("Home", viewModel.UserLocations[0].Description);
                Assert.AreEqual(43.0M, viewModel.UserLocations[0].Latitude);
                Assert.AreEqual(-79.0M, viewModel.UserLocations[0].Longitude);
            }
        }

        [TestMethod]
        public void ManagePersonalLocationsViewModelAddLocation()
        {
            MockPersonalLocationService service = InitializeMockPersonalLocationService();
            using (ManagePersonalLocationsViewModel viewModel = new ManagePersonalLocationsViewModel(new PersonalLocationModel(service)))
            {
                viewModel.Latitude = 41.0;
                viewModel.Longitude = -75.0;
                viewModel.Description = "Mom's house";
                viewModel.AddLocationCommand.Execute(null);
                Assert.AreEqual(3, viewModel.UserLocations.Count);
                Assert.AreEqual(2, viewModel.UserLocations[2].Id);
                Assert.AreEqual("Mom's house", viewModel.UserLocations[2].Description);
                Assert.AreEqual(41.0M, viewModel.UserLocations[2].Latitude);
                Assert.AreEqual(-75.0M, viewModel.UserLocations[2].Longitude);
            }
        }

    }
}
